package com.example.demo.mapper;

import com.example.demo.pojo.dto.UserPageDTO;
import com.example.demo.pojo.entity.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    @Select("select * from user where username=#{username};")
    User getByUsername(String username);

    @Insert("insert into user (username,password,name,phone,create_time) values " +
            "(#{username},#{password},#{name},#{phone},#{createTime})")
    void insert(User user);

    @Select("select * from user where id=#{userId}")
    User getById(Long userId);

    void update(User user);

    Page<User> pageQuery(UserPageDTO userPageDTO);

    @Select("select count(id) from user where age>=10 and age<18")
    Integer getAge10();

    @Select("select count(id) from user where age>=18 and age<48")
    Integer getAge18();

    @Select("select count(id) from user where age>=45 and age<=55")
    Integer getAge45();

    @Select("select COUNT(id) from user")
    Integer getAll();
}
